﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DIProject.Dictionary
{
    public partial class Catalog : Form
    {
        public Catalog()
        {
            InitializeComponent();
        }
        

        private void Catalog_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dictionary.Catalog' table. You can move, or remove it, as needed.
            this.catalogTableAdapter.Fill(this.dictionary.Catalog,DIProject.Data.Sync.IsAdmin);

        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {

            CatalogDetails cd = new CatalogDetails(DIProject.Util.ActionType.Insert, Int32.MinValue, this);
            cd.Show(this);
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            dataGridView1.Rows[e.RowIndex].Selected = true;
            DataRowView dr = dataGridView1.SelectedRows[0].DataBoundItem as DataRowView;
            if (dr != null)
            {
                DIProject.DataSets.Dictionary.CatalogRow cr = dr.Row as DIProject.DataSets.Dictionary.CatalogRow;
                if (cr != null)
                {
                    if (cr.Id == 0)
                    {
                        MessageBox.Show("Нельзя редактировать этот элемент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    CatalogDetails cd = new CatalogDetails(DIProject.Util.ActionType.Update, cr.Id,this);
                    //cd.MdiParent = this;
                    cd.Show(this);
                }
            }
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            this.catalogTableAdapter.Fill(this.dictionary.Catalog, DIProject.Data.Sync.IsAdmin);
        }
    }
}